/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.awt.Color;
import java.awt.Point;
import java.util.ArrayList;
import javax.swing.ImageIcon;

/**
 *
 * @author Jeppe
 */
public abstract class ChessPiece1 {

    private final String name;
    private final Color color;
    private final boolean colorBool;
    private final Point position;
    private ImageIcon imageIcon;

    /**
     * 
     * @param name
     * @param color if true the piece becomes white, false if black
     * @param position 
     */
    public ChessPiece1(String name, boolean color, Point position) {
        this.name = name;
        this.colorBool =color;
        String billedFarve;
        if(color){
            this.color = Color.WHITE;
            billedFarve="Hvid";
        }else{
            this.color = Color.BLACK;
            billedFarve = "Sort";
        }
        this.imageIcon = new ImageIcon(getClass().getResource("/images/chesspieces/"+billedFarve+name+".png"));
        this.position = position;
	System.out.println(name+" : "+position.getX()+","+position.getY());
    }

    public final boolean canMoveTo(int x, int y) {
        boolean possible = false;
        if (x <= 8 && x >= 0 && y <= 8 && y >= 0) {
            if (x != position.x && y != position.y) {
                possible = true;
            }
        }
        return possible;
    }

    public String positionToFields(int x, int y) {
        String xNy;
        switch (x) {
            case 1:
                xNy = "A";
                break;
            case 2:
                xNy = "B";
                break;
            case 3:
                xNy = "C";
                break;
            case 4:
                xNy = "D";
                break;
            case 5:
                xNy = "E";
                break;
            case 6:
                xNy = "F";
                break;
            case 7:
                xNy = "G";
                break;
            case 8:
                xNy = "H";
                break;
            default: xNy= "Fejl";
        }
        return xNy+y;
    }
    
    public abstract ArrayList<Point> possibleMoves();
    
    public String show(){
        String str;
        String col;
        if(colorBool){
            col = "Hvid";
        }else{
            col = "Sort";
        }
        str = col+" "+name+" "+position.x+", "+position.y+"\n kan flyttes til ";
        for (int i = 0; i < possibleMoves().size(); i++) {
            
        }
        return str;
    }

    public ImageIcon getImageIcon() {
        return imageIcon;
    }    

    public Point getPosition() {
        return position;
    }
    
    
    /**
     * 
     * @return true if white, false if black 
     */
    public boolean getColor() {
        return colorBool;
    }

    
    
}
